<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册页面</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f5f5f5;
            padding: 20px;
        }
        #background{

            position: fixed;
            z-index: -1;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            object-fit: cover;
        }

        .container {
            max-width: 376px;
            margin: 32px auto;
            background-color: #fff;
            border: 1px solid #ccc;
            padding: 21px;
        }

        h2 {
            text-align: center;
            margin-bottom: 30px;
        }

        .form-group {
            margin-bottom: 20px;
        }

        label {
            display: block;
            font-weight: bold;
            margin-bottom: 5px;
        }

        input[type="text"],
        input[type="password"] {
            width: 100%;
            padding: 10px;
            border-radius: 4px;
            border: 1px solid #ccc;
        }

        button {
            width: 100%;
            padding: 10px;
            background-color: #4caf50;
            border: none;
            color: #fff;
            cursor: pointer;
            border-radius: 4px;
        }

        button:hover {
            background-color: #45a049;
        }
    </style>
</head>
<body>
<img src="img/image3.jpg" id="background">
<div class="container">
    <h2>用户注册</h2>
    <form>
        <div class="form-group">
            <label for="username">用户名:</label>
            <input type="text" id="username" placeholder="请输入用户名">
        </div>
        <div class="form-group">
            <label for="password">密码:</label>
            <input type="password" id="password" placeholder="请输入密码">
        </div>
        <div class="form-group">
            <label for="confirm_password">确认密码:</label>
            <input type="password" id="confirm_password" placeholder="请确认密码">
        </div>
        <button type="submit" >注册</button>
    </form>
</div>
<script type="text/javascript" src="js/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="layui/layui.js"></script>
<script type="text/javascript" src="js/public.js"></script>
<script>
    document.querySelector("form").addEventListener("submit", function(event) {
        event.preventDefault(); // 阻止表单默认提交行为

        // 获取输入框的值
        var username = document.getElementById("username").value;
        var password = document.getElementById("password").value;
        var confirmPassword = document.getElementById("confirm_password").value;

        // 检查用户名和密码是否为空
        if (username === "" || password === "" || confirmPassword === "") {
            alert("用户名和密码不能为空");
            return;
        }

        // 检查密码和确认密码是否匹配
        if (password !== confirmPassword) {
            alert("密码和确认密码不匹配");
            return;
        }

        // 发送注册请求到后端（这里仅为示例，实际需要发送请求到后端）
        var data = {
            username: username,
            password: password
        };

        // 这里使用了fetch API来发送POST请求，你也可以使用其他的AJAX库
        fetch(url+user.add, {
            method: "POST",
            headers: {
                "Content-Type": "application/json"
            },
            body: JSON.stringify(data)
        })
            .then(function(response) {
                if (response.ok) {
                    // 注册成功
                    alert("注册成功");
                    location.href="login.html"
                } else {
                    // 注册失败
                    alert("注册失败");
                }
            })
            .catch(function(error) {
                console.log(error);
            });

        // 清空输入框的值
        document.getElementById("username").value = "";
        document.getElementById("password").value = "";
        document.getElementById("confirm_password").value = "";
    });
</script>
</body>
</html>